package com.devplatform.util;

import com.devplatform.pojo.user.User;
import lombok.Data;

@Data
public class UserContextHolder {
    private static final ThreadLocal<User> context = new ThreadLocal<>();

    public static void setUser(User user) {
        context.set(user);
    }

    public static Long getUserId() {
        if (context.get() == null) {
            return null;
        }
        return context.get().getUserId();
    }

    public static String getUsername() {
        return context.get().getUsername();
    }

    public static void clear() {
        context.remove();
    }
}

